package com.suyang.syt.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.suyang.syt.model.dto.AjaxObj;
import com.suyang.syt.service.interfaces.CitysService;
import com.suyang.syt.util.AppUtil;
import com.suyang.syt.util.EmptyUtil;
import com.suyang.syt.util.StringUtil;

@Controller
@RequestMapping("/area")
public class AppCitysController {

	@Autowired
	private CitysService citysService;

	@RequestMapping(value = "/findArea", method = RequestMethod.POST)
	@ResponseBody
	public AjaxObj findArea(HttpServletRequest request, String lat, String lng) {
		try {
			String msg = AppUtil.validateSn(request);
			if ("验证成功".equals(msg)) {
				if (EmptyUtil.isNotEmpty(lat) && EmptyUtil.isNotEmpty(lng)) {
					return citysService.findArea(Double.parseDouble(lat), Double.parseDouble(lng));
				} else {
					return citysService.findArea(0, 0);
				}
			} else {
				return new AjaxObj(0, msg);
			}
		} catch (Exception e) {
			return new AjaxObj(0, StringUtil.ERROR_MSG);
		}
	}

	@RequestMapping(value = "/findHasOpened", method = RequestMethod.POST)
	@ResponseBody
	public AjaxObj findHasOpened(HttpServletRequest request) {
		try {
			String msg = AppUtil.validateSn(request);
			if ("验证成功".equals(msg)) {
				return citysService.findHasOpened();
			} else {
				return new AjaxObj(0, msg);
			}
		} catch (Exception e) {
			return new AjaxObj(0, StringUtil.ERROR_MSG);
		}
	}

}
